package layer
{
	import map.data.BirthPoint;
	
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import view.BirthPointView;

	public class BirthPointLayer extends BaseLayer
	{
		private var _points:Vector.<BirthPointView>;
		private var _currentSelected:BirthPointView;
		public function BirthPointLayer()
		{
			super();
			_points = new Vector.<BirthPointView>();
		}
		
		public function addBirthPoint(birthPoint:BirthPoint):void
		{
			for each(var bpv:BirthPointView in _points)
			{
				if(bpv.birthPoint.equals(birthPoint))
				{
					return;
				}
			}
			bpv = new BirthPointView(birthPoint);
			bpv.addEventListener(MouseEvent.CLICK,onClick);
			addChild(bpv);
			_points.push(bpv);
		}
		
		private function onClick(event:MouseEvent):void
		{
			if(_optionType == MapEditor.SELECT)
			{
				for each(var bpv:BirthPointView in _points)
				{
					bpv.selected = false;
				}
				_currentSelected = bpv = event.currentTarget as BirthPointView;
				bpv.selected = true;
			}
		}
		
		override public function deleteCurrentSelected():void
		{
			if(_currentSelected)
			{
				_points.splice(_points.indexOf(_currentSelected),1);
				_currentSelected.removeEventListener(MouseEvent.CLICK,onClick);
				removeChild(_currentSelected);
			}
			_currentSelected = null;
		}
		
		override public function getData():*
		{
			var result:Vector.<BirthPoint> = new Vector.<BirthPoint>();
			for each(var bpv:BirthPointView in _points)
			{
				result.push(bpv.birthPoint);
			}
			return result;
		}
	}
}